package com.lintf.sharding.sphere.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lintf.business.entity.SysUser;
import com.lintf.common.base.AjaxResult;
import com.lintf.common.page.BaseController;
import com.lintf.common.page.TableDataInfo;
import com.lintf.sharding.sphere.service.ISysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@Slf4j
@RestController
@RequestMapping("/sysUser")
public class SysUserController extends BaseController {

    @Autowired
    private ISysUserService sysUserService;

    @GetMapping("/getSysUserListByPageHelperM1")
    public AjaxResult getSysUserListByPageHelperM1() {
        return AjaxResult.success(sysUserService.getSysUserListByPageHelperM1());
    }

    @GetMapping("/getSysUserListByPageHelperM2")
    public AjaxResult getSysUserListByPageHelperM2() {
        return AjaxResult.success(sysUserService.getSysUserListByPageHelperM2());
    }

    @GetMapping("/getSysUserListByPageHelperToUtils")
    public AjaxResult getSysUserListByPageHelperToUtils() {
        return AjaxResult.success(sysUserService.getSysUserListByPageHelperToUtils());
    }

    @GetMapping("/getSysUserListByMyBatisPlus")
    public AjaxResult getSysUserListByMyBatisPlus() {
        return AjaxResult.success(sysUserService.getSysUserListByMyBatisPlus());
    }

    @GetMapping("/getSysUserListByMyBatisPlusToUtils")
    public AjaxResult getSysUserListByMyBatisPlusToUtils() {
        return AjaxResult.success(sysUserService.getSysUserListByMyBatisPlusToUtils());
    }

    @GetMapping("/getSysUserListByBaseController")
    public TableDataInfo getSysUserListByBaseController() {
        startPage();
        LambdaQueryWrapper<SysUser> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(SysUser::getCreateTime);
        return getDataTable(sysUserService.list(wrapper));
    }

    @RequestMapping("/save")
    public void save() {
        SysUser sysUser = new SysUser();
//        sysUser.setUid(Long.valueOf(RandomUtil.randomNumbers(8)));
        sysUser.setCreateTime(new Date())
                .setUpdateTime(new Date());
        if (sysUserService.save(sysUser)) {
            log.debug("请求成功");
        } else
            log.error("请求失败");
    }

}
